package tesis.sin.bd;

import com.db4o.Db4oEmbedded;
import com.db4o.ObjectContainer;
import com.db4o.query.Query;

public class BaseDatos {

	private static ObjectContainer db;

	private static ObjectContainer getDb() {
		if(db == null)
			 setDb(Db4oEmbedded.openFile(Db4oEmbedded.newConfiguration(), "D://Benjamin//Workspace//SIN//prueba"));
		return db;
	}

	private static void setDb(ObjectContainer db) {
		BaseDatos.db = db;
	}
	
	public static Object recuperarObjeto(Class clase, String identificador, Object valorIdentificador)
	{
		Query query = db.query();
		query.constrain(clase);
		query.descend(identificador).constrain(valorIdentificador);
		return query.execute().next();
	}
	
	public static void guardarObjeto(Object objeto)
	{
		getDb().store(objeto);
	}
}
